﻿using CloudDcPc.Entity;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CloudDcPc.FuckDlg
{
    /// <summary>
    /// GzAddDlg.xaml 的交互逻辑
    /// </summary>
    public partial class GzAddDlg : Window
    {
        ObservableCollection<Gz> all_Gz = null;
        public GzAddDlg(ObservableCollection<Gz> all_Gz)
        {
            InitializeComponent();
            this.all_Gz = all_Gz;
            List<User> list_approver = App.UserBean.GetUsersByField("type", "3");
            cb_approver.ItemsSource = list_approver;
        }



        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            string sign_name = txt_sign_name.Text;
            string department = txt_department.Text;
            string phone = txt_phone.Text;
            string doer = txt_doer.Text;
            string approver = ((User)cb_approver.SelectedItem).User_num;
            Gz gz = new Gz()
            {
                Sign_name = sign_name,
                Department = department,
                Phone = phone,
                Doer = doer,
                Approver = approver
            };
            if (sign_name == "" || department == "" || phone == "" || doer == "" || approver == "")
            {
                MessageBox.Show("请将信息填写完整！");
                return;
            }

            if (App.GzBean.HasGz(sign_name, department))
            {
                MessageBox.Show("已经存在有相同的签单人和单位的记录！");
                return;
            }

            if (App.GzBean.AddGz(gz))
            {
                MessageBox.Show("添加成功！");
                all_Gz.Add(gz);
                this.Close();
            }else
            {
                MessageBox.Show("添加失败！");
            }
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

    }
}
